<script type="text/javascript">

$(function(){
		set_province();
	});
	function state_change_address()
	{
	  if (xmlhttp.readyState==4)
	  {
	  	// 4 = "loaded"
	  	if (xmlhttp.status==200)
	    {
	    	// 200 = "OK"
	    	r = xmlhttp.responseText.split('&');
	    	document.getElementById(r[0]).innerHTML=r[1];
	    }
	  	else
	    {
	    	//alert("Problem retrieving data:" + xmlhttp.statusText);
	    }
	  }
	}
	function set_province()
	{
		url=base_url + "/address/get_province/";
		send_query(url,state_change_address);
	}
	function set_city(province_id)
	{
		if(province_id == -1)
		{
			document.getElementById("city").innerHTML="";
			return;
		}
		url=base_url + "/address/get_city/"+province_id;
		send_query(url,state_change_address);
	}
	function set_zone(city_id)
	{
		if(city_id == -1)
		{
			document.getElementById("zone").innerHTML="";
			return;
		}
		url=base_url + "/address/get_zone/"+city_id;
		send_query(url,state_change_address);
	}
	function set_zone_detail(zone_id)
	{
		if(zone_id == -1)
		{
			document.getElementById("zone_detail").innerHTML="";
			return;
		}
		url=base_url + "/address/get_zone_detail/"+zone_id;
		send_query(url,state_change_address);
	}
	function province_changed(){
		pid = document.getElementById('province').value;
		set_city(pid);
		set_zone(-1);
		set_zone_detail(-1);
	}
	function city_changed(){
		cid = document.getElementById('city').value;
		set_zone(cid);
		set_zone_detail(-1);
	}
	function zone_changed(){
		zid = document.getElementById('zone').value;
		set_zone_detail(zid);
	}
	function submit_address(){
		province=document.getElementById("province").value;
		city=document.getElementById("city").value;
		zone=document.getElementById("zone").value;
		zone_detail=document.getElementById("zone_detail").value;
		more=document.getElementById("more").value;
		if(!zone_detail || !more)
		{
			alert("输入的联系地址有误或者不完整。");
			return;
		}
		url=base_url + "/address/submit/"+
						zone_detail+"/"+
						more+"/";
		send_query(url,state_change_address_submit);
	}
	function state_change_address_submit()
	{
		if (xmlhttp.readyState==4)
	  	{
	  		// 4 = "loaded"
	  		if (xmlhttp.status==200)
	    	{
	    		// 200 = "OK"
	    		r = xmlhttp.responseText;
	    		if(r == "Address error")
	    		{
	    			alert("输入的联系地址有误或者不完整。");
	    		}
	    		window.location.reload();
	    		//alert(r);
	    		//document.getElementById("your_address").innerHTML=r;
	    	}
	  		else
	    	{
	    		//alert("Problem retrieving data:" + xmlhttp.statusText);
	   	 	}
	  	}
	}
</script>
<div>
	省<select id="province" onchange="province_changed();">
	</select>
	市<select id="city" onchange="city_changed();">
	</select>
	区<select id="zone" onchange="zone_changed();">
	</select>
	区域<select id="zone_detail">
	</select>
	详细<input id="more" type="text">
	<input type="button" value="确定" onclick="submit_address();">
</div>